package com.xinchili.mysqlSimulateRedis;

import com.xinchili.mysqlSimulateRedis.service.RedisService;
import com.xinchili.mysqlSimulateRedis.service.impl.MysqlCacheService;
import com.xinchili.mysqlSimulateRedis.service.impl.RedisCacheService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
public class AutoRedisConfiguration {

    // 当不存在RedisTemplate时，使用MysqlCacheService
    @Bean
    @ConditionalOnMissingBean(value = {RedisTemplate.class, RedisService.class})
    public RedisService mysqlCacheService() {
        return new MysqlCacheService();
    }

    // 当存在RedisTemplate时，可以使用RedisCacheService
    @Bean
    @ConditionalOnBean(RedisTemplate.class)
    @ConditionalOnMissingBean(RedisService.class)
    public RedisService redisCacheService() {
        // 这里需要你提供RedisCacheService的实现
        return new RedisCacheService();
    }


}
